const Service = require('egg').Service;
class bookdetailService extends Service {
    async GetBookDetail(bid, headers, querytoken) {
        const{ctx,logger}=this
        let has_ex = 0;
        if(ctx.query.state){
            has_ex = ctx.query.state
        }
        if(ctx.query.has_ex){
            has_ex = ctx.query.has_ex;
        }
        var data = {
            ip: headers ? headers : "0.0.0.0",
            token:querytoken ? querytoken : "",
            has_ex:has_ex,
            book: null
        };
        try{
            let rs_data = await ctx.service.curlService.curlPost("api/v1.0/book/getBookDetailForWeb",{
                book_id:bid,
                token:querytoken
            })
            if (rs_data.res_code == 1) {
                data =await ctx.helper.formatBook2(data, rs_data.msg, bid);
                let qr_data = await ctx.service.wxService.getTempQrCode("bid_" + bid)
                data.qrcode_url = qr_data.msg.url ? qr_data.msg.url : "";
                return {rescode:2,data:data}
            } else {
                return {rescode:"error","err":"first"}
            }
            return;
        }catch(err){
            logger.error("bookauthRouter find error :",err)
            return {rescode:"error","err":"two"}
        }
    }

}
module.exports = bookdetailService;
